package com.haitaoit.chengquan.module.home.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.home.model.RecruitListModel;
import com.haitaoit.chengquan.view.CircleImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/20.
 */
public class RecruitAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<RecruitListModel> list;
    private String type;

    public void setType(String type) {
        this.type = type;
    }

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public RecruitAdapter(Context context) {
        this.context = context;
    }

    public List<RecruitListModel> getList() {
        return list;
    }

    public void setList(List<RecruitListModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_job_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.job_detele.setVisibility(View.GONE);
        holder.job_lin10.setVisibility(View.GONE);

        holder.job_itemll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RecruitAdapter.this.backCall.deal(R.id.job_itemll, position);
            }
        });

        ImageLoader.getInstance().displayImage(list.get(position).getImg_ur(), holder.center_img);
        holder.job_title.setText(list.get(position).getTitle());
        holder.job_addtime.setText(list.get(position).getAddtime());

        Drawable img = null;
        if (type.equals("1")) {
            img = context.getResources().getDrawable(R.mipmap.img37);
            holder.job_tv1.setText(list.get(position).getArea());
            holder.job_name.setText(list.get(position).getCompanyname());
            holder.post_salary.setText(list.get(position).getPost_salary());
//            "工作经验：" +
            holder.job_tv2.setText(list.get(position).getExperience_requirements());
        } else if (type.equals("2")) {
            img = context.getResources().getDrawable(R.mipmap.pic18);
            holder.job_tv1.setText("最高学历：" + list.get(position).getEducation());
            holder.job_name.setText(list.get(position).getName());
            holder.post_salary.setText(list.get(position).getExpected_salary());
//            "工作经验：" +
            holder.job_tv2.setText(list.get(position).getWork_year());
        }
        img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
        holder.job_tv1.setCompoundDrawables(img, null, null, null);
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.center_img)
        CircleImageView center_img;
        @ViewInject(R.id.job_title)
        TextView job_title;
        @ViewInject(R.id.job_itemll)
        LinearLayout job_itemll;
        @ViewInject(R.id.job_detele)
        LinearLayout job_detele;
        @ViewInject(R.id.job_lin10)
        View job_lin10;
        @ViewInject(R.id.job_tv1)
        TextView job_tv1;
        @ViewInject(R.id.job_tv2)
        TextView job_tv2;
        @ViewInject(R.id.job_addtime)
        TextView job_addtime;
        @ViewInject(R.id.post_salary)
        TextView post_salary;
        @ViewInject(R.id.job_name)
        TextView job_name;
    }
}
